import path from 'path'
import resolve from 'rollup-plugin-node-resolve' // 依赖引用插件解析第三方模块
import commonjs from 'rollup-plugin-commonjs' // commonjs模块转换插件
import postcss from 'postcss'
import  autoprefixer from 'autoprefixer'
import { eslint } from 'rollup-plugin-eslint' // eslint插件
import ts from 'rollup-plugin-typescript2'
import scss from 'rollup-plugin-scss'
const getPath = _path => path.resolve(__dirname, _path)


const extensions = [
  '.js',
  '.ts',
  '.tsx'
]


// ts
const tsPlugin = ts({
  tsconfig: getPath('./tsconfig.json'), // 导入本地ts配置
  extensions
})


// eslint
const esPlugin = eslint({
  throwOnError: true,
  include: ['src/**/*.ts'],
  exclude: ['node_modules/**', 'lib/**']
})


// 基础配置
const commonConf = {
  input: getPath('./plugins/index.ts'),
  plugins: [
    resolve(extensions),
    commonjs(),
    esPlugin,
    tsPlugin,
    scss({
      // Run postcss processor before output
      // eslint-disable-next-line no-unused-vars
      processor: (css) => postcss([autoprefixer({ "overrideBrowserslist": [
        "> 1%",
        "last 2 versions",
        "firefox 4",
        "opera 10"
      ] })]),
    })
  ]
}
// 需要导出的模块类型
const outputMap = [
  {
    file: getPath('lib/index.js'), // 输出的文件途径
    format: 'umd',
    name: 'vite_ts', //挂载到window的名字
    sourcemap: true
  },
]


const buildConf = options => Object.assign({}, commonConf, options)


export default buildConf({ output: outputMap })